﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using System.Data;

namespace DataAccess
{
    public class ThietBi_info
    {
        public int matb { get; set; }
        public string tentb { get; set; }
        public decimal gia { get; set; }

        public static List<ThietBi_info> All()
        {
            return CBO.FillCollection<ThietBi_info>(DataProvider.Instance.ExecuteReader("ThietBi_GetAll"));
        }
        public static DataSet GetAll()
        {
            try
            {
                return DataProvider.Instance.ExecuteDataset("ThietBi_GetAll");
            }
            catch (Exception)
            {

                return null;
            }
        }
        public static bool Add(string tentb, string gia)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("ThietBi_Insert", tentb, float.Parse(gia));
                return Convert.ToInt32(rs) > 0;
            }
            catch (Exception e)
            {
                return BatLoi.ThongBao(e.Message);
            }
        }
        public static bool Update(string matb, string tentb, string gia)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("ThietBi_Update",int.Parse(matb), tentb,float.Parse(gia));
                    return Convert.ToInt32(rs) > 0;
            }
            catch (Exception e)
            {
                return BatLoi.ThongBao(e.Message);
            }
        }
        public static bool Delete(string matb)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ThietBi_Delete",int.Parse(matb));
                return rs > 0;
            }
            catch (Exception e)
            {
                return BatLoi.ThongBao(e.Message);
            }
        }
        public static List<ThietBi_info> GetByName(string name)
        {
            try
            {
                return CBO.FillCollection<ThietBi_info>(DataProvider.Instance.ExecuteReader("NhanVien_GetByName", name));
            }
            catch
            {
                return null;
            }
        }
        public static List<NhanVien_Info> GetByID(string manv)
        {
            try
            {
                return CBO.FillCollection<NhanVien_Info>(DataProvider.Instance.ExecuteReader("NhanVien_GetByID", manv));
            }
            catch
            {
                return null;
            }
        }
        public static DataSet GetByMaLoaiPhong(string maloaiphong)
        {
            try
            {
                return DataProvider.Instance.ExecuteDataset("ThietBi_GetByMaLoaiPhong", maloaiphong);
            }
            catch
            {
                return null;
            }
        }
        public static List<NhanVien_Info> GetByCMND(string soCMND)
        {
            try
            {
                return CBO.FillCollection<NhanVien_Info>(DataProvider.Instance.ExecuteReader("NhanVien_GetByCMND", Convert.ToInt32(soCMND)));
            }
            catch
            {
                return null;
            }
        }

    }
}
